package com.design.design.pattern.creational.builder.v2;

/**
 * 静态内部类的建造者模式 （日常应用常见）
 * 把实体类和对应的builder创建在一个类中
 *
 * 这种方式更加简易
 */
public class Course {
    private String courseName;
    private String coursePPT;
    private String courseVideo;
    private String courseArticle;
    private String courseFAQ;

    public Course(CourseBuiler courseBuiler) {
        this.courseName = courseBuiler.courseName;
        this.coursePPT = courseBuiler.coursePPT;
        this.courseArticle = courseBuiler.courseArticle;
        this.courseFAQ = courseBuiler.courseFAQ;
        this.courseVideo = courseBuiler.courseVideo;
    }
    @Override
    public String toString() {
        return "Course{" +
                "courseName='" + courseName + '\'' +
                ", coursePPT='" + coursePPT + '\'' +
                ", courseVideo='" + courseVideo + '\'' +
                ", courseArticle='" + courseArticle + '\'' +
                ", courseFAQ='" + courseFAQ + '\'' +
                '}';
    }

    /**
     * 使用静态内部类构建建造者
     */
    public static class CourseBuiler {
        private String courseName;
        private String coursePPT;
        private String courseVideo;
        private String courseArticle;
        private String courseFAQ;

        /**
         * 返回 CourseBuiler 类型，可以变成链式调用
         * @param courseName
         * @return
         */
        public CourseBuiler buildCourseNane(String courseName) {
            this.courseName = courseName;
            return this;
        }
        public CourseBuiler buildCoursePPT(String coursePPT) {
            this.coursePPT = coursePPT;
            return this;
        }

        public CourseBuiler buildCourseVideo(String courseVideo) {
            this.courseVideo = courseVideo;
            return this;
        }

        public CourseBuiler buildCourseArticle(String courseArticle) {
            this.courseArticle = courseArticle;
            return this;
        }

        public CourseBuiler buildCourseFAQ(String courseFAQ) {
            this.courseFAQ = courseFAQ;
            return this;
        }

        public Course build() {
            return new Course(this);
        }

    }
}
